home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / dflat8.zip / VIDEO.C < prev    next >
Text File  |  1991-09-30  |  6KB  |  248 lines

  1. /* --------------------- video.c -------------------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. static unsigned video_address;
  6. /* -- read a rectangle of video memory into a save buffer -- */
  7. void getvideo(RECT rc, void far *bf)
  8. {
  9.     int ht = RectBottom(rc)-RectTop(rc)+1;
  10.     int bytes_row = (RectRight(rc)-RectLeft(rc)+1) * 2;
  11.     unsigned vadr = vad(RectLeft(rc), RectTop(rc));
  12.     hide_mousecursor();
  13.     while (ht--)    {
  14.         movedata(video_address, vadr, FP_SEG(bf),
  15.                 FP_OFF(bf), bytes_row);
  16.         vadr += SCREENWIDTH*2;
  17.         bf = (char far *)bf + bytes_row;
  18.     }
  19.     show_mousecursor();
  20. }
  21.  
  22. /* -- write a rectangle of video memory from a save buffer -- */
  23. void storevideo(RECT rc, void far *bf)
  24. {
  25.     int ht = RectBottom(rc)-RectTop(rc)+1;
  26.     int bytes_row = (RectRight(rc)-RectLeft(rc)+1) * 2;
  27.     unsigned vadr = vad(RectLeft(rc), RectTop(rc));
  28.     hide_mousecursor();
  29.     while (ht--)    {
  30.         movedata(FP_SEG(bf), FP_OFF(bf), video_address,
  31.                 vadr, bytes_row);
  32.         vadr += SCREENWIDTH*2;
  33.         bf = (char far *)bf + bytes_row;
  34.     }
  35.     show_mousecursor();
  36. }
  37.  
  38. /* -------- read a character of video memory ------- */
  39. unsigned int GetVideoChar(int x, int y)
  40. {
  41.     int c;
  42.     hide_mousecursor();
  43.     c = peek(video_address, vad(x,y));
  44.     show_mousecursor();
  45.     return c;
  46. }
  47.  
  48. /* -------- write a character of video memory ------- */
  49. void PutVideoChar(int x, int y, int c)
  50. {
  51.     if (x < SCREENWIDTH && y < SCREENHEIGHT)    {
  52.         hide_mousecursor();
  53.         poke(video_address, vad(x,y), c);
  54.         show_mousecursor();
  55.     }
  56. }
  57.  
  58. static int isAncestor(WINDOW wnd, WINDOW awnd)
  59. {
  60.     while (wnd != NULL)    {
  61.         if (wnd == awnd)
  62.             return TRUE;
  63.         wnd = GetParent(wnd);
  64.     }
  65.     return FALSE;
  66. }
  67.  
  68. static RECT PrepRect(WINDOW wnd, RECT rc)
  69. {
  70.     if (!TestAttribute(wnd, NOCLIP))    {
  71.         while (GetParent(wnd))    {
  72.             wnd = GetParent(wnd);
  73.             rc = subRectangle(rc, ClientRect(wnd));
  74.         }
  75.     }
  76.     return rc;
  77. }
  78.  
  79. int CharInView(WINDOW wnd, int x, int y)
  80. {
  81.     int x1 = GetLeft(wnd)+x;
  82.     int y1 = GetTop(wnd)+y;
  83.  
  84.     if (!TestAttribute(wnd, NOCLIP))    {
  85.         WINDOW wnd1 = GetParent(wnd);
  86.         while (wnd1 != NULL)    {
  87.             /* --- clip character to parent's borders -- */
  88.             RECT rc = ClientRect(wnd1);
  89.             if (!InsideRect(x1, y1, rc))
  90.                 return FALSE;
  91.             wnd1 = GetParent(wnd1);
  92.         }
  93.     }
  94.     return (x1 < SCREENWIDTH && y1 < SCREENHEIGHT);
  95. }
  96.  
  97. /* -------- write a character to a window ------- */
  98. void wputch(WINDOW wnd, int c, int x, int y)
  99. {
  100.     if (isVisible(wnd) && CharInView(wnd, x, y))    {
  101.         int x1 = GetLeft(wnd)+x;
  102.         int y1 = GetTop(wnd)+y;
  103.         WINDOW nwnd = NextWindow(wnd);
  104.         while (nwnd != NULL)    {
  105.             if (isVisible(nwnd) && !isAncestor(wnd, nwnd))    {
  106.                 RECT rc = PrepRect(nwnd, WindowRect(nwnd));
  107.                 if (InsideRect(x1,y1,rc))
  108.                     return;
  109.             }
  110.             nwnd = NextWindow(nwnd);
  111.         }
  112.         hide_mousecursor();
  113.         poke(video_address,
  114.             vad(x1,y1),(c & 255) |
  115.                 (clr(foreground, background) << 8));
  116.         show_mousecursor();
  117.     }
  118. }
  119.  
  120. /* ------- write a string to a window ---------- */
  121. void wputs(WINDOW wnd, void *s, int x, int y)
  122. {
  123.     int x1 = GetLeft(wnd)+x;
  124.     int y1 = GetTop(wnd)+y;
  125.     if (x1 < SCREENWIDTH && y1 < SCREENHEIGHT)    {
  126.         int fg = foreground;
  127.         int bg = background;
  128.         unsigned char *str, *ss;
  129.         int *ln, *cp1, *cp2;
  130.         int len;
  131.  
  132.         if ((ss = malloc(400)) != NULL)    {
  133.             if ((ln = malloc(400)) != NULL)    {
  134.                 WINDOW nwnd = NextWindow(wnd);
  135.                 cp1 = cp2 = ln;
  136.                 strncpy(ss, s, 399);
  137.                 str = ss;
  138.                 while (*str)    {
  139.                     if (*str == CHANGECOLOR)    {
  140.                         str++;
  141.                         foreground = (*str++) & 0x7f;
  142.                         background = (*str++) & 0x7f;
  143.                         continue;
  144.                     }
  145.                     if (*str == RESETCOLOR)    {
  146.                         foreground = fg & 0x7f;
  147.                         background = bg & 0x7f;
  148.                         str++;
  149.                         continue;
  150.                     }
  151.                     *cp1++ = (*str & 255) |
  152.                         (clr(foreground, background) << 8);
  153.                     str++;
  154.                 }
  155.                 foreground = fg;
  156.                 background = bg;
  157.                 len = (int)(cp1-ln);
  158.                 if (x1+len > SCREENWIDTH)
  159.                     len = SCREENWIDTH-x1;
  160.  
  161.                 /* --- clip  the line for overlapping windows --- */
  162.                 while (len > 0 && nwnd != NULL)    {
  163.                     if (isVisible(nwnd) && !isAncestor(wnd, nwnd))    {
  164.                         int x2;
  165.                         RECT rc = PrepRect(nwnd, WindowRect(nwnd));
  166.                         while (len && InsideRect(x1,y1,rc))    {
  167.                             x1++;
  168.                             ln++;
  169.                             --len;
  170.                         }
  171.                         if (len)    {
  172.                             x2 = x1+len-1;
  173.                             while (len && InsideRect(x2,y1,rc))    {
  174.                                 --x2;
  175.                                 --len;
  176.                             }
  177.                         }
  178.                     }
  179.                     nwnd = NextWindow(nwnd);
  180.                 }
  181.  
  182.                 if (!TestAttribute(wnd, NOCLIP))    {
  183.                     /* -- clip the line to within ancestor windows -- */
  184.                     nwnd = GetParent(wnd);
  185.                     while (len > 0 && nwnd != NULL)    {
  186.                         if (isVisible(nwnd))    {
  187.                             int x2;
  188.                             RECT rc = PrepRect(nwnd, ClientRect(nwnd));
  189.                             while (len && !InsideRect(x1,y1,rc))    {
  190.                                 x1++;
  191.                                 ln++;
  192.                                 --len;
  193.                             }
  194.                             if (len)    {
  195.                                 x2 = x1+len-1;
  196.                                 while (len && !InsideRect(x2,y1,rc))    {
  197.                                     --x2;
  198.                                     --len;
  199.                                 }
  200.                             }
  201.                         }
  202.                         nwnd = GetParent(nwnd);
  203.                     }
  204.                 }
  205.  
  206.                 if (len > 0)    {
  207.                     hide_mousecursor();
  208.                     movedata(FP_SEG(ln), FP_OFF(ln),
  209.                         video_address, vad(x1,y1), len*2);
  210.                     show_mousecursor();
  211.                 }
  212.                 free(cp2);
  213.             }
  214.             free(ss);
  215.         }
  216.     }
  217. }
  218.  
  219. /* --------- get the current video mode -------- */
  220. void get_videomode(void)
  221. {
  222.     videomode();
  223.     /* ---- Monochrome Display Adaptor or text mode ---- */
  224.     if (ismono())
  225.         video_address = 0xb000;
  226.     else
  227.         /* ------ Text mode -------- */
  228.         video_address = 0xb800 + video_page;
  229. }
  230.  
  231. /* --------- scroll the window. d: 1 = up, 0 = dn ---------- */
  232. void scroll_window(WINDOW wnd, RECT rc, int d)
  233. {
  234.     union REGS regs;
  235.     hide_mousecursor();
  236.     regs.h.cl = RectLeft(rc);
  237.     regs.h.ch = RectTop(rc);
  238.     regs.h.dl = RectRight(rc);
  239.     regs.h.dh = RectBottom(rc);
  240.     regs.h.bh = clr(WndForeground(wnd),WndBackground(wnd));
  241.     regs.h.ah = 7 - d;
  242.     regs.h.al = 1;
  243.     int86(VIDEO, ®s, ®s);
  244.     show_mousecursor();
  245. }
  246.  
  247.  
  248.